%{
#include <stdlib.h>

int inside_spec;
int context_main;
int context_sub ;
int set_path(void);
int end_path(void);

typedef enum context_enum {
CONTEXT_NONE=0,
CONTEXT_CLOSE,
CONTEXT_SPEC,
CONTEXT_FILE,
CONTEXT_COMMAND,
CONTEXT_SRC,
CONTEXT_SET,
CONTEXT_DIR,
CONTEXT_DEFAULT
 } context_t;

%}

%option noyywrap
/* Parser file for Updater config */

DIGIT [0-9]
CHAR  [a-zA-Z]
WORD  [:alpha:][:digit:]
TAG_OPEN <WORD>
TAG_CLOSE </WORD>

%%
[:space:] 
[:space:]*"</>" {printf("\nBegin of config\n");set_context( CONTEXT_CLOSE); } 

[:space:]*"<spec>" {printf("\nBegin of config\n");set_context( CONTEXT_SPEC); } 
[:space:]*"</spec>" {printf("\nEnd of config\n");unset_context( CONTEXT_SPEC); } 

[:space:]*"<file>" {printf("\nBegin of file tag\n"); set_context( CONTEXT_FILE);} 
[:space:]*"</file>" {printf("\nEnd of file tag\n"); unset_context( CONTEXT_FILE);}

[:space:]*"<command>" {printf("\nBegin of file tag\n"); set_context(CONTEXT_COMMAND);} 
[:space:]*"</command>" {printf("\nEnd of file tag\n");unset_context(CONTEXT_COMMAND);}

[:space:]*"<src>" {printf("\nBegin of src tag\n"); set_context(CONTEXT_SRC); }
[:space:]*"</src>" {printf("\nEnd of src tag\n");  unset_context(CONTEXT_SRC); }

[:space:]*"<set>" {printf("\nBegin of set tag\n"); set_context(CONTEXT_SET); }
[:space:]*"</set>" {printf("\nEnd of set tag\n"); unset_context(CONTEXT_SET); }

[:space:]*"<dir>" {printf("\nBegin of set tag\n"); set_context(CONTEXT_DIR); }
[:space:]*"</dir>" {printf("\nEnd of set tag\n"); unset_context(CONTEXT_DIR); }

[:space:]*"<default>" {printf("\nBegin of set tag\n"); set_context(CONTEXT_DEFAULT); }
[:space:]*"</default>" {printf("\nEnd of set tag\n");unset_context(CONTEXT_DEFAULT); }

[:space:]*"<path>" {printf("\nBegin of set tag\n"); set_path(); }
[:space:]*"</path>" {printf("\nEnd of set tag\n");end_path(); }
%%

main( argc, argv )
int argc;
char **argv;
{
	++argv, --argc;  /* skip over program name */
	if ( argc > 0 )
		yyin = fopen( argv[0], "r" );
	else
		yyin = stdin;

	yylex();

}


int set_context(context_t context)
{
	switch(context)
	{
		case CONTEXT_SPEC:
			printf("CONTEXT_SPEC opened\n");
		break;
		case CONTEXT_FILE:
			printf("CONTEXT_FILE opened\n");
		break;
		case CONTEXT_DIR:
			printf("CONTEXT_DIR opened\n");
		break;
		case CONTEXT_COMMAND:
			printf("CONTEXT_COMMAND opened\n");
		break;
		case CONTEXT_SRC:
			printf("CONTEXT_SRC opened\n");
		break;
		case CONTEXT_SET:
			printf("CONTEXT_SET opened\n");
		break;
		case CONTEXT_DEFAULT:
			printf("CONTEXT_DEFAULT opened\n");
		break;

	}
}

int unset_context(context_t context)
{
	switch(context)
	{
	}
}

int set_path()
{
	printf("The path is: |%s|\n", yytext);
	return(0);
}

int end_path()
{
	return(0);
}
